﻿

//创建GoogleMap
//panelMap - 显示地图的对象区域
//showScale - 是否显示改变大小的控件 true false
//showLargeControl - 是否显示切换控件  true false
//showTypeControl - 是否显示切换显示类型的按钮
//showZoom - 是否显示左下角的小地图
//zoomSize - 视觉距离
var clickListener;
var GoogleMapCreate = function(panelMap, showScale, showLargeControl, showTypeControl, showZoom, zoomSize,latLng) {
    myMap = new GMap2(panelMap);
    if (showLargeControl) {
        myMap.addControl(new GLargeMapControl());
    }
    else {
        myMap.addControl(new GSmallMapControl());
    }


    if (showTypeControl) {
        myMap.addControl(new GMapTypeControl());
    }


    if (showScale) {
        myMap.addControl(new GScaleControl());
    }

    if (showZoom) {
        myMap.addControl(new GOverviewMapControl());
    }

    myMap.enableDoubleClickZoom();
    myMap.enableContinuousZoom();

    myMap.setCenter(latLng, zoomSize, G_NORMAL_MAP);
    return myMap;
};

//监听Map事件
var GoogleMapAddEvent = function(myMap, eventName, fun) {
    clickListener = GEvent.addListener(myMap, eventName, fun);
};

//移除时间监听
var GoogleMapRemoveEvent = function(myMap, eventName) {
    GEvent.removeListener(clickListener);
};


//在指定坐标上显示tip提示
var GoogleMapShowTipExpand = function(myMap, point, text, sHTML) {
    myMap.openInfoWindowHtml(point, "<b>" + text + "!</b>",
                { maxContent: sHTML,
                    maxTitle: text
                });
};

//在指定坐标上显示tip提示
var GoogleMapShowTip = function(myMap, point, sHTML) {
    myMap.openInfoWindowHtml(point, sHTML);
};

//在指定坐标上显示tip简单提示
var GoogleMapShowTipText = function(myMap, point, text) {
    myMap.openInfoWindowHtml(point, document.createTextNode(text));
};


//在指定坐标上加入地标
var GoogleMapNewMarker = function(myMap, point, option) {
    var marker = new GMarker(point, option);
    myMap.addOverlay(marker);
    return marker;
};


//根据坐标点取得X坐标
var GoogleMapPointX = function(point) {
    return point.lat();
};

//根据坐标点取得Y坐标
var GoogleMapPointY = function(point) {
    return point.lng();
};
